﻿

using System.Collections.Generic;
using System.Text;
using UtilLib;

public enum EMudColorMode
{
    //默认颜色 转化
    Normal = 0,
    //上色
    Color = 1,
    //错误颜色
    Err = 2,
    //弹出提示
    Pop = 3,
};

public enum EMudColor
{
    GRN = 0,
    RED = 1,
    YEL = 2,
    BLU = 3,
    MAG = 4,
    CYN = 5,
    WHT = 6,
    WHI = 7,
    BLK = 8,
    HIG = 9,
    HIR = 10,
    HIY = 11,
    HIB = 12,
    HIM = 13,
    HIC = 14,
    HIW = 15,
    HIK = 16,
    HIO = 17,
    aqua = 18,
    black = 19,
    blue = 20,
    brown = 21,
    cyan = 22,
    darkblue = 23,
    fuchsia = 24,
    green = 25,
    grey = 26,
    lightblue = 27,
    lime = 28,
    magenta = 29,
    maroon = 30,
    navy = 31,
    olive = 32,
    orange = 33,
    purple = 34,
    red = 35,
    silver = 36,
    teal = 37,
    white = 38,
    yellow = 39,
};

public static partial class Efun
{
    public const string NOR = "</color>";

    public const string GRN = "<color=#008000ff>";
    public const string RED = "<color=#800000ff>";
    public const string YEL = "<color=#808000ff>";
    public const string BLU = "<color=#000080ff>";
    public const string MAG = "<color=#800080ff>";
    public const string CYN = "<color=#008080ff>";
    public const string WHT = "<color=#000000ff>";
    public const string WHI = "<color=#C0C0C0ff>";
    public const string BLK = "<color=#808080ff>";

    public const string HIG = "<color=#00ff00ff>";
    public const string HIR = "<color=#ff0000ff>";
    public const string HIY = "<color=#ffff00ff>";
    public const string HIB = "<color=#0000ffff>";
    public const string HIM = "<color=#ff00ffff>";
    public const string HIC = "<color=#00ffffff>";
    public const string HIW = "<color=#ffffffff>";
    public const string HIK = "<color=#000000ff>";

    public const string HIO = "<color=#ffa500ff>";

    public const string aqua = "<color=#00ffffff>";
    public const string black = "<color=#000000ff>";
    public const string blue = "<color=#0000ffff>";
    public const string brown = "<color=#a52a2aff>";
    public const string cyan = "<color=#00ffffff>";
    public const string darkblue = "<color=#0000a0ff>";
    public const string fuchsia = "<color=#ff00ffff>";
    public const string green = "<color=#008000ff>";
    public const string grey = "<color=#808080ff>";
    public const string lightblue = "<color=#add8e6ff>";
    public const string lime = "<color=#00ff00ff>";
    public const string magenta = "<color=#ff00ffff>";
    public const string maroon = "<color=#800000ff>";
    public const string navy = "<color=#000080ff>";
    public const string olive = "<color=#808000ff>";
    public const string orange = "<color=#ffa500ff>";
    public const string purple = "<color=#800080ff>";
    public const string red = "<color=#ff0000ff>";
    public const string silver = "<color=#c0c0c0ff>";
    public const string teal = "<color=#008080ff>";
    public const string white = "<color=#ffffffff>";
    public const string yellow = "<color=#ffff00ff>";
    public const string royalblue = "<color=#4169E1ff>";
    public const string plum = "<color=#DDA0DDff>";
    public const string firebrick = "<color=#B22222ff>";
    public const string deepskyblue = "<color=#00BFFFff>";
    public const string greenyellow = "<color=#ADFF2Fff>";
    public const string springgreen = "<color=#00FF7Fff>";
    public const string darkturquoise = "<color=#00CED1ff>";

    public const string CBLK = "#808080ff";
    public const string CRED = "#800000ff";
    public const string CGRN = "#008000ff";
    public const string CYEL = "#808000ff";
    public const string CBLU = "#000080ff";
    public const string CMAG = "#800080ff";
    public const string CCYN = "#008080ff";
    public const string CWHT = "#000000ff";
    public const string CWHI = "#C0C0C0ff";

    public const string CHIK = "#000000ff";
    public const string CHIR = "#ff0000ff";
    public const string CHIG = "#00ff00ff";
    public const string CHIY = "#ffff00ff";
    public const string CHIB = "#0000ffff";
    public const string CHIM = "#ff00ffff";
    public const string CHIC = "#00ffffff";
    public const string CHIW = "#ffffffff";

    public const string CHIO = "#ffa500ff";


    #region 配置内替换

    // 颜色替换表
    public static Dictionary<string, string> DictMudColor = new Dictionary<string, string>
        {
            { "#NOR#", NOR },

            { "#GRN#", GRN },
            { "#RED#", RED },
            { "#YEL#", YEL },
            { "#BLU#", BLU },
            { "#MAG#", MAG },
            { "#CYN#", CYN },
            { "#WHT#", WHT },
            { "#WHI#", WHI },
            { "#BLK#", BLK },

            { "#HIG#", HIG },
            { "#HIR#", HIR },
            { "#HIY#", HIY },
            { "#HIB#", HIB },
            { "#HIM#", HIM },
            { "#HIC#", HIC },
            { "#HIW#", HIW },
            { "#HIK#", HIK },

            { "#HIO#", HIO },

            { "#aqua#", aqua },
            { "#black#", black },
            { "#blue#", blue },
            { "#brown#", brown },
            { "#cyan#", cyan },
            { "#darkblue#", darkblue },
            { "#fuchsia#", fuchsia },
            { "#green#", green },
            { "#grey#", grey },
            { "#lightblue#", lightblue },
            { "#lime#", lime },
            { "#magenta#", magenta },
            { "#maroon#", maroon },
            { "#navy#", navy },
            { "#olive#", olive },
            { "#orange#", orange },
            { "#purple#", purple },
            { "#red#", red },
            { "#silver#", silver },
            { "#teal#", teal },
            { "#white#", white },
            { "#yellow#", yellow },
            { "#royalblue#", royalblue },
            { "#plum#", plum },
            { "#firebrick#", firebrick },
            { "#deepskyblue#", deepskyblue },
            { "#greenyellow#", greenyellow },
            { "#springgreen#", springgreen },
            { "#darkturquoise#", darkturquoise },

        };
    public static string ColorReplace(this string text, string color)
    {
        string result = GRN;
        if (!DictMudColor.TryGetValue(color, out result))
        {
            result = GRN;
        }
        return $"{result}{text}{NOR}";
    }
    public static string ColorReplace(this string text)
    {
        string arg = text;
        if (arg.IsNullOrEmpty())
        {
            return arg;
        }
        foreach (var kvp in DictMudColor)
        {
            arg = arg.Replace(kvp.Key, kvp.Value);
        }
        return arg;
    }
    public static string ColorRemove(this string text)
    {
        string arg = text;
        if (arg.IsNullOrEmpty())
        {
            return arg;
        }
        foreach (var kvp in DictMudColor)
        {
            arg = arg.Replace(kvp.Key, "");
        }
        return arg;
    }

    #endregion

    #region 上色
    //上色表
    public static Dictionary<EMudColor, string> DictMudColorE = new Dictionary<EMudColor, string>
        {
            { EMudColor.GRN, GRN },
            { EMudColor.RED, RED },
            { EMudColor.YEL, YEL },
            { EMudColor.BLU, BLU },
            { EMudColor.MAG, MAG },
            { EMudColor.CYN, CYN },
            { EMudColor.WHT, WHT },
            { EMudColor.WHI, WHI },
            { EMudColor.BLK, BLK },

            { EMudColor.HIG, HIG },
            { EMudColor.HIR, HIR },
            { EMudColor.HIY, HIY },
            { EMudColor.HIB, HIB },
            { EMudColor.HIM, HIM },
            { EMudColor.HIC, HIC },
            { EMudColor.HIW, HIW },
            { EMudColor.HIK, HIK },

            { EMudColor.HIO, HIO },

            { EMudColor.aqua, aqua },
            { EMudColor.black, black },
            { EMudColor.blue, blue },
            { EMudColor.brown, brown },
            { EMudColor.cyan, cyan },
            { EMudColor.darkblue, darkblue },
            { EMudColor.fuchsia, fuchsia },
            { EMudColor.green, green },
            { EMudColor.grey, grey },
            { EMudColor.lightblue, lightblue },
            { EMudColor.lime, lime },
            { EMudColor.magenta, magenta },
            { EMudColor.maroon, maroon },
            { EMudColor.navy, navy },
            { EMudColor.olive, olive },
            { EMudColor.orange, orange },
            { EMudColor.purple, purple },
            { EMudColor.red, red },
            { EMudColor.silver, silver },
            { EMudColor.teal, teal },
            { EMudColor.white, white },
            { EMudColor.yellow, yellow },
        };
    public static string AddColorText(this object text, EMudColor ecolor)
    {
        if (!DictMudColorE.TryGetValue(ecolor, out var code))
        {
            return text.ToString();
        }
        return $"{code}{text}</color>";
    }
    public static void AddColorText(this StringBuilder sb, object text, EMudColor ecolor, bool newline = false)
    {
        sb.Append(text.AddColorText(ecolor));
        if (newline)
        {
            sb.AppendLine();
        }
    }
    public static string AddColorText(this object text, string color)
    {
        return $"<color={color}>{text}</color>";
    }

    #endregion

    public static string AddColorText(this object text, EGender gender)
    {
        EMudColor ecolor = EMudColor.GRN;
        switch (gender)
        {
            case EGender.男性:
            case EGender.雄性:
                ecolor = EMudColor.HIG;
                break;
            case EGender.女性:
            case EGender.雌性:
                ecolor = EMudColor.HIM;
                break;
            default:
                break;
        };
        return (AddColorText(text, ecolor));
    }
}
